# Huawei Technologies Co.,Ltd.

set(PROMISE_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/promise.txt)
set(PROMISE_JS ${CMAKE_CURRENT_SOURCE_DIR}/promise.js)
set(PROMISE_BIN ${CMAKE_CURRENT_BINARY_DIR}/promise.abc)
set(PROMISE_PA ${CMAKE_CURRENT_BINARY_DIR}/promise.pa)
set(PROMISE_VERIFY ${CMAKE_CURRENT_SOURCE_DIR}/verify.sh)

set(RUNTIME_ARGUMENTS --boot-panda-files=${PANDA_BINARY_ROOT}/pandastdlib/arkstdlib.abc --load-runtimes=\"ecmascript\" --compiler-enable-jit=false ${PROMISE_BIN} _GLOBAL::func_main_0)

add_custom_command(
    OUTPUT ${PROMISE_OUTPUT}
    COMMENT "running javascript promise testcase"
    COMMAND ${PANDA_RUN_PREFIX} $<TARGET_FILE:es2panda> ${PROMISE_JS} --dump-assembly --output ${PROMISE_BIN} > ${PROMISE_PA}
    COMMAND rm -f ${PROMISE_OUTPUT}
    COMMAND ${PANDA_RUN_PREFIX} $<TARGET_FILE:ark> ${RUNTIME_ARGUMENTS} > ${PROMISE_OUTPUT}
    COMMAND bash ${PROMISE_VERIFY} ${PROMISE_OUTPUT}
)
add_custom_target(promise
    DEPENDS ${PROMISE_OUTPUT} ${PROMISE_VERIFY}
)
add_dependencies(promise es2panda ark)
add_dependencies(ecmascript_common_tests promise)
